//
//  SplashCore.m
//  HHNMobileCore
//
//  Created by huhmf on 15/8/18.
//  Copyright (c) 2015年 huhmf. All rights reserved.
//

#import "SplashCore.h"
#import "RequestSplashApi.h"
#import <MJExtension.h>
#define KVersion @"1.9"
@implementation SplashCore

-(void)requestSplashWithSuccBlock:(void (^)(NSDictionary *dict))succBlock failBLock:(void (^)())failBlock
{
    
    RequestSplashApi *api=[[RequestSplashApi alloc] initWithAppVersion:KVersion andPlatForm:@"2"];
    api.ignoreCache=NO;

    
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        NSError *err;
        
        HHLog(@"log = %@",request.responseString.mj_JSONData);
        if (request.responseString.mj_JSONData) {
            NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:request.responseString.mj_JSONData
                                                                 options:NSJSONReadingMutableContainers
                                                                   error:&err];
            if(err) {
                LogError(THome, @"RequestSplashApi,json to dict error：%@", err.localizedDescription);
                failBlock();
                return;
            }
            HHLog(@"RequestSplashApi,Succ isDataFromCache:%d",[api isDataFromCache]);
            
            NSInteger code=[(NSNumber *)[dict valueForKey:@"code"] integerValue];
            if (code<=-1) {
                succBlock(nil);
                return;
            }
            
            if([[dict valueForKey:@"data"] isKindOfClass:[NSDictionary class]])
            {
                
                NSDictionary *dict_data=[dict valueForKey:@"data"];
                succBlock(dict_data);
                return;
            }
        }
      
        
    } failure:^(YTKBaseRequest *request) {
        LogError(THome, @"RequestSplashApi error:%@", request.requestTask.error.localizedDescription);
        failBlock();
    }];
}

@end
